﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VirginiaForms
{
    public class MyEncoder
    {
        /// <summary>
        /// 明文
        /// </summary>
        public string PlainText { get; set; }
        /// <summary>
        /// 密文
        /// </summary>
        public string Cypher { get; set; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 加密动作
        /// </summary>
        public void Encryption()
        {
            //加密过程
            for (int i = 0, j = 0; i < PlainText.Length; i++, j++)
            {
                if (j % Key.Length == 0)
                    j = 0;
                int num = (CharToNum(PlainText[i]) + CharToNum(Key[j])) % 26;
                Cypher += Convert.ToChar(num + 'a');
            }
        }
        /// <summary>
        /// 返回指定字符在字母表中的序号（从0开始）
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        private int CharToNum(char ch)
        {
            return ch - 'a';
        }
    }
}
